<?php
include("include/config.inc.php");
if(!isset($_SESSION['s_activId']))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
}
else
{
	if(isset($_POST['Submit']))
	{
		$itemName  = 	isset($_POST['itemName']) && $_POST['itemName'] !='' ? $_POST['itemName'] : "";
		$itemUnit  = 	isset($_POST['itemUnit']) && $_POST['itemUnit'] !='' ? $_POST['itemUnit'] : "";
		
	  $insertItem = "INSERT INTO item(itemName,itemUnit)VALUES('".$itemName."','".$itemUnit."')";
	  $insertItemRes = mysql_query($insertItem);
	  if(!$insertItemRes)
	  {
	  	echo "Insert Fail";
	  }
	  else
	  {
	  	header("Location:item.php");
	  }
	}
	
	$itemArray = array();
	$i = 0;
	$selectItem = "SELECT itemId,itemName,itemUnit
	                 FROM item
	                ORDER BY itemName";
	$selectItemRes = mysql_query($selectItem);
	while($itemRow = mysql_fetch_array($selectItemRes))
	{
		$itemArray[$i]['itemId']   = $itemRow['itemId'];
		$itemArray[$i]['itemName'] = $itemRow['itemName'];
		$itemArray[$i]['itemUnit'] = $itemRow['itemUnit'];
		$i++;
	}
	$unitValueArr[0]  = 'Kg';
	$unitOutPutArr[0] = 'Kg';
	$unitValueArr[1]  = 'Litre';
	$unitOutPutArr[1] = 'Litre';
	$unitValueArr[2]  = 'Pieces';
	$unitOutPutArr[2] = 'Pieces';
}
include("./bottom.php");
$smarty->assign("itemArray",$itemArray);
$smarty->assign("unitValueArr",$unitValueArr);
$smarty->assign("unitOutPutArr",$unitOutPutArr);
$smarty->display("item.tpl");
?>